<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>git 操作指南 | 20秒的勇气</title>
    <meta name="generator" content="VuePress 1.5.3">
    <script>var _hmt = _hmt || [];
      (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?01611e9c2d4c65531fe791d0a83e6ebd";
        var s = document.getElementsByTagName("script")[0]; 
        s.parentNode.insertBefore(hm, s);
      })()</script>
    <meta name="description" content="欢迎来到wenbintian的博客">
    <link rel="preload" href="/blog/assets/css/0.styles.5dc057b1.css" as="style"><link rel="preload" href="/blog/assets/js/app.2a047d56.js" as="script"><link rel="preload" href="/blog/assets/js/2.cc145974.js" as="script"><link rel="preload" href="/blog/assets/js/36.7239d917.js" as="script"><link rel="prefetch" href="/blog/assets/js/10.dc9f6a74.js"><link rel="prefetch" href="/blog/assets/js/11.f7ecaf96.js"><link rel="prefetch" href="/blog/assets/js/12.4363725a.js"><link rel="prefetch" href="/blog/assets/js/13.0fd4b251.js"><link rel="prefetch" href="/blog/assets/js/14.edc7bd5f.js"><link rel="prefetch" href="/blog/assets/js/15.647c0964.js"><link rel="prefetch" href="/blog/assets/js/16.2e8857c5.js"><link rel="prefetch" href="/blog/assets/js/17.1c7cc9ee.js"><link rel="prefetch" href="/blog/assets/js/18.bf88a22d.js"><link rel="prefetch" href="/blog/assets/js/19.1433c5a8.js"><link rel="prefetch" href="/blog/assets/js/20.713720d3.js"><link rel="prefetch" href="/blog/assets/js/21.51a3d47b.js"><link rel="prefetch" href="/blog/assets/js/22.04488762.js"><link rel="prefetch" href="/blog/assets/js/23.b9337410.js"><link rel="prefetch" href="/blog/assets/js/24.d0d5b562.js"><link rel="prefetch" href="/blog/assets/js/25.e76a54ef.js"><link rel="prefetch" href="/blog/assets/js/26.006d0afa.js"><link rel="prefetch" href="/blog/assets/js/27.38ec3468.js"><link rel="prefetch" href="/blog/assets/js/28.c8cf7077.js"><link rel="prefetch" href="/blog/assets/js/29.70f03487.js"><link rel="prefetch" href="/blog/assets/js/3.9bfe5560.js"><link rel="prefetch" href="/blog/assets/js/30.3e6d6ba9.js"><link rel="prefetch" href="/blog/assets/js/31.1dbd85cb.js"><link rel="prefetch" href="/blog/assets/js/32.208e4272.js"><link rel="prefetch" href="/blog/assets/js/33.979228dd.js"><link rel="prefetch" href="/blog/assets/js/34.6ad6fae2.js"><link rel="prefetch" href="/blog/assets/js/35.59b3e591.js"><link rel="prefetch" href="/blog/assets/js/37.a8305f70.js"><link rel="prefetch" href="/blog/assets/js/38.7e3197cd.js"><link rel="prefetch" href="/blog/assets/js/39.1bb3ad3b.js"><link rel="prefetch" href="/blog/assets/js/4.3b6a7e49.js"><link rel="prefetch" href="/blog/assets/js/40.bc263e99.js"><link rel="prefetch" href="/blog/assets/js/41.4ee25f6a.js"><link rel="prefetch" href="/blog/assets/js/42.37c6cc26.js"><link rel="prefetch" href="/blog/assets/js/43.9a40d780.js"><link rel="prefetch" href="/blog/assets/js/44.2eda0bb6.js"><link rel="prefetch" href="/blog/assets/js/45.ce3372d9.js"><link rel="prefetch" href="/blog/assets/js/46.17e44796.js"><link rel="prefetch" href="/blog/assets/js/47.f845ed6d.js"><link rel="prefetch" href="/blog/assets/js/5.bc6e1aa4.js"><link rel="prefetch" href="/blog/assets/js/6.e0f80af7.js"><link rel="prefetch" href="/blog/assets/js/7.c808e2d2.js"><link rel="prefetch" href="/blog/assets/js/8.902b76dc.js"><link rel="prefetch" href="/blog/assets/js/9.9bb8a7fe.js">
    <link rel="stylesheet" href="/blog/assets/css/0.styles.5dc057b1.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/blog/" class="home-link router-link-active"><!----> <span class="site-name">20秒的勇气</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/blog/knowledge/" class="nav-link router-link-active">
  知识篇
</a></div><div class="nav-item"><a href="/blog/notes/" class="nav-link">
  随身笔记
</a></div> <a href="https://github.com/wenbintian" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/blog/knowledge/" class="nav-link router-link-active">
  知识篇
</a></div><div class="nav-item"><a href="/blog/notes/" class="nav-link">
  随身笔记
</a></div> <a href="https://github.com/wenbintian" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><a href="/blog/knowledge/book/" class="sidebar-heading clickable"><span>读书篇</span> <span class="arrow right"></span></a> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><a href="/blog/knowledge/tool/" class="sidebar-heading clickable router-link-active open"><span>工具篇</span> <span class="arrow down"></span></a> <ul class="sidebar-links sidebar-group-items"><li><a href="/blog/knowledge/tool/tool1.html" aria-current="page" class="active sidebar-link">git 操作指南</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/knowledge/tool/tool1.html#创建新仓库以及到正常提交代码" class="sidebar-link">创建新仓库以及到正常提交代码</a></li><li class="sidebar-sub-header"><a href="/blog/knowledge/tool/tool1.html#工作流" class="sidebar-link">工作流</a></li><li class="sidebar-sub-header"><a href="/blog/knowledge/tool/tool1.html#stash-暂存操作" class="sidebar-link">stash 暂存操作</a></li><li class="sidebar-sub-header"><a href="/blog/knowledge/tool/tool1.html#branch-分支操作" class="sidebar-link">branch 分支操作</a></li><li class="sidebar-sub-header"><a href="/blog/knowledge/tool/tool1.html#commit-命令" class="sidebar-link">commit 命令</a></li><li class="sidebar-sub-header"><a href="/blog/knowledge/tool/tool1.html#回退操作" class="sidebar-link">回退操作</a></li><li class="sidebar-sub-header"><a href="/blog/knowledge/tool/tool1.html#cherry-pick-操作" class="sidebar-link">cherry-pick 操作</a></li><li class="sidebar-sub-header"><a href="/blog/knowledge/tool/tool1.html#worktree-操作" class="sidebar-link">worktree 操作</a></li><li class="sidebar-sub-header"><a href="/blog/knowledge/tool/tool1.html#统计git项目行数" class="sidebar-link">统计git项目行数</a></li><li class="sidebar-sub-header"><a href="/blog/knowledge/tool/tool1.html#参考" class="sidebar-link">参考</a></li></ul></li><li><a href="/blog/knowledge/tool/tool2.html" class="sidebar-link">移动端适配之postcss-px-to-viewport</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><a href="/blog/knowledge/css/" class="sidebar-heading clickable"><span>CSS篇</span> <span class="arrow right"></span></a> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><a href="/blog/knowledge/js/" class="sidebar-heading clickable"><span>JS篇</span> <span class="arrow right"></span></a> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="git-操作指南"><a href="#git-操作指南" class="header-anchor">#</a> git 操作指南</h1> <h2 id="创建新仓库以及到正常提交代码"><a href="#创建新仓库以及到正常提交代码" class="header-anchor">#</a> 创建新仓库以及到正常提交代码</h2> <ol><li>在 github 网站上点击<code>new</code>, 进入项目配置页面。</li> <li>填写项目名：<code>Repository name</code>。</li> <li>填写项目描述：<code>Description</code>。</li> <li>选择私有还是公开：<code>Public</code> 和 <code>Private</code>。</li> <li>点击<code>Create repository</code> 完成创建
<img src="https://img-blog.csdnimg.cn/20200815233509931.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDY1MzMyOQ==,size_16,color_FFFFFF,t_70#pic_center" alt="在这里插入图片描述"> <img src="https://img-blog.csdnimg.cn/2020081523495564.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDY1MzMyOQ==,size_16,color_FFFFFF,t_70#pic_center" alt="在这里插入图片描述"></li> <li>复制这个链接
<img src="https://img-blog.csdnimg.cn/20200815235146769.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDY1MzMyOQ==,size_16,color_FFFFFF,t_70#pic_center" alt="在这里插入图片描述"></li> <li><code>git clone https://github.com/wenbintian/test.git</code> 此时会生成一个包含<code>.git</code>文件夹的项目
<code>git clone https://github.com/wenbintian/test.git</code> 新的名称 可用于重新命名项目名称</li></ol> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>test<span class="token operator">&gt;</span>git clone https://github.com/wenbintian/test.git
D:<span class="token punctuation">\</span>test<span class="token operator">&gt;</span>git clone https://github.com/wenbintian/test.git project-name
</code></pre></div><ol start="8"><li>新增<code>README.md</code>文件</li></ol> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>test<span class="token punctuation">\</span>test<span class="token operator">&gt;</span>echo <span class="token string">'# test'</span> <span class="token operator">&gt;&gt;</span> README.md
</code></pre></div><ol start="9"><li>此时就可以正常的提交了</li></ol> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>test<span class="token punctuation">\</span>test<span class="token operator">&gt;</span>git <span class="token function">add</span> <span class="token builtin class-name">.</span>

D:<span class="token punctuation">\</span>test<span class="token punctuation">\</span>test<span class="token operator">&gt;</span>git commit -m <span class="token string">'第一次提交'</span>
<span class="token punctuation">[</span>master <span class="token punctuation">(</span>root-commit<span class="token punctuation">)</span> 33c940a<span class="token punctuation">]</span> <span class="token string">'第一次提交'</span>
 <span class="token number">1</span> <span class="token function">file</span> changed, <span class="token number">1</span> insertion<span class="token punctuation">(</span>+<span class="token punctuation">)</span>
 create mode <span class="token number">100644</span> README.md

D:<span class="token punctuation">\</span>test<span class="token punctuation">\</span>test<span class="token operator">&gt;</span>git push -u origin master
Enumerating objects: <span class="token number">3</span>, done.
Counting objects: <span class="token number">100</span>% <span class="token punctuation">(</span><span class="token number">3</span>/3<span class="token punctuation">)</span>, done.
Writing objects: <span class="token number">100</span>% <span class="token punctuation">(</span><span class="token number">3</span>/3<span class="token punctuation">)</span>, <span class="token number">238</span> bytes <span class="token operator">|</span> <span class="token number">238.00</span> KiB/s, done.
Total <span class="token number">3</span> <span class="token punctuation">(</span>delta <span class="token number">0</span><span class="token punctuation">)</span>, reused <span class="token number">0</span> <span class="token punctuation">(</span>delta <span class="token number">0</span><span class="token punctuation">)</span>
To https://github.com/wenbintian/test.git
 * <span class="token punctuation">[</span>new branch<span class="token punctuation">]</span>      master -<span class="token operator">&gt;</span> master
Branch <span class="token string">'master'</span> <span class="token builtin class-name">set</span> up to track remote branch <span class="token string">'master'</span> from <span class="token string">'origin'</span><span class="token builtin class-name">.</span>
</code></pre></div><h2 id="工作流"><a href="#工作流" class="header-anchor">#</a> 工作流</h2> <ul><li><code>Working Tree</code> 当前的工作区域</li> <li><code>Index/Stage</code> 暂存区域，和 git stash 命令暂存的地方不一样。使用 git add xx，就可以将 xx 添加近 Stage 里面</li> <li><code>Repository</code> 提交的历史，即使用 git commit 提交后的结果</li></ul> <p><img src="/blog/tool/git2.png" alt="在这里插入图片描述"> <img src="/blog/tool/git1.png" alt="在这里插入图片描述"></p> <h2 id="stash-暂存操作"><a href="#stash-暂存操作" class="header-anchor">#</a> stash 暂存操作</h2> <h3 id="使用场景"><a href="#使用场景" class="header-anchor">#</a> 使用场景</h3> <ul><li>当准备提交代码时发现有一个文件的改动是多余的，想直接还原的又担心之后想要查看这些改动的代码，想保存它又不想增加一个多余的提交，此时就可以使用<code>stash</code>缓存起来。</li> <li>当开发一个需求开发一半的时候，来了个紧急 bug，正常情况可以把完成一半的代码<code>commit</code>提交到本地仓库，然后创建切换到一个新的分支去修改 bug。但这样的话往往 log 上会有大量不必要的记录。<code>stash</code>就能解决这样的需求，使用<code>git stash</code>把当前完成一半的代码缓存起来推入<code>Git</code>的栈中，然后把紧急的代码改完后提交，最后再<code>git stash pop</code>把完成一半的代码拉回到本地代码中</li></ul> <h3 id="操作汇总"><a href="#操作汇总" class="header-anchor">#</a> 操作汇总</h3> <div class="language-bash extra-class"><pre class="language-bash"><code>PS D:<span class="token punctuation">\</span>project<span class="token punctuation">\</span>git<span class="token punctuation">\</span>test-project<span class="token operator">&gt;</span> <span class="token function">git</span> stash <span class="token builtin class-name">help</span>
usage: <span class="token function">git</span> stash list <span class="token punctuation">[</span><span class="token operator">&lt;</span>options<span class="token operator">&gt;</span><span class="token punctuation">]</span>
   or: <span class="token function">git</span> stash show <span class="token punctuation">[</span><span class="token operator">&lt;</span>stash<span class="token operator">&gt;</span><span class="token punctuation">]</span>
   or: <span class="token function">git</span> stash drop <span class="token punctuation">[</span>-q<span class="token operator">|</span>--quiet<span class="token punctuation">]</span> <span class="token punctuation">[</span><span class="token operator">&lt;</span>stash<span class="token operator">&gt;</span><span class="token punctuation">]</span>
   or: <span class="token function">git</span> stash <span class="token punctuation">(</span> pop <span class="token operator">|</span> apply <span class="token punctuation">)</span> <span class="token punctuation">[</span>--index<span class="token punctuation">]</span> <span class="token punctuation">[</span>-q<span class="token operator">|</span>--quiet<span class="token punctuation">]</span> <span class="token punctuation">[</span><span class="token operator">&lt;</span>stash<span class="token operator">&gt;</span><span class="token punctuation">]</span>
   or: <span class="token function">git</span> stash branch <span class="token operator">&lt;</span>branchname<span class="token operator">&gt;</span> <span class="token punctuation">[</span><span class="token operator">&lt;</span>stash<span class="token operator">&gt;</span><span class="token punctuation">]</span>
   or: <span class="token function">git</span> stash <span class="token punctuation">[</span>save <span class="token punctuation">[</span>--patch<span class="token punctuation">]</span> <span class="token punctuation">[</span>-k<span class="token operator">|</span>--<span class="token punctuation">[</span>no-<span class="token punctuation">]</span>keep-index<span class="token punctuation">]</span> <span class="token punctuation">[</span>-q<span class="token operator">|</span>--quiet<span class="token punctuation">]</span>
                       <span class="token punctuation">[</span>-u<span class="token operator">|</span>--include-untracked<span class="token punctuation">]</span> <span class="token punctuation">[</span>-a<span class="token operator">|</span>--all<span class="token punctuation">]</span> <span class="token punctuation">[</span><span class="token operator">&lt;</span>message<span class="token operator">&gt;</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
   or: <span class="token function">git</span> stash <span class="token function">clear</span>
</code></pre></div><h3 id="操作详解"><a href="#操作详解" class="header-anchor">#</a> 操作详解</h3> <h4 id="git-stash-list"><a href="#git-stash-list" class="header-anchor">#</a> git stash list</h4> <p>列出您当前拥有的存储条目
如：</p> <div class="language-bash extra-class"><pre class="language-bash"><code>PS D:<span class="token punctuation">\</span>project<span class="token punctuation">\</span>git<span class="token punctuation">\</span>test-project<span class="token operator">&gt;</span> <span class="token function">git</span> stash list
stash@<span class="token punctuation">{</span><span class="token number">0</span><span class="token punctuation">}</span>: On master: Uncommitted changes before Update at <span class="token number">2019</span>/9/30 <span class="token number">14</span>:27
stash@<span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">}</span>: On master: Uncommitted changes before Update at <span class="token number">2019</span>/9/23 <span class="token number">9</span>:39
stash@<span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span>: On master: Uncommitted changes before Update at <span class="token number">2019</span>/8/15 <span class="token number">18</span>:00
</code></pre></div><h4 id="git-stash-show"><a href="#git-stash-show" class="header-anchor">#</a> git stash show</h4> <p>显示存储条目中记录的更改，作为隐藏内容和提交首次创建存储条目时的提交之间的差异（注意只是列出具体哪些文件的差异，具体代码的差异是没有列出来的）
<strong>git stash show 'stash@{0}'</strong> 可以查看某一条的差异，注意 stash@{0} 需要单引号
如：</p> <div class="language-bash extra-class"><pre class="language-bash"><code>  PS D:<span class="token punctuation">\</span>project<span class="token punctuation">\</span>git<span class="token punctuation">\</span>test-project<span class="token operator">&gt;</span> <span class="token function">git</span> stash show <span class="token string">'stash@{0}'</span>
 app/common/api-class.js                            <span class="token operator">|</span>     <span class="token number">4</span> +-
 app/config/config.js                               <span class="token operator">|</span>     <span class="token number">4</span> +
 app/his5/menuFrame/index.js                        <span class="token operator">|</span>     <span class="token number">6</span> +-
 app/test/demo-zoeRoute.js                          <span class="token operator">|</span>     <span class="token number">8</span> +-
</code></pre></div><h4 id="git-stash-show-stash-0-p"><a href="#git-stash-show-stash-0-p" class="header-anchor">#</a> git stash show 'stash@{0}' -p</h4> <p>可以查看某一条里代码的差异.</p> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>project<span class="token punctuation">\</span>git<span class="token punctuation">\</span>web-portal<span class="token operator">&gt;</span> <span class="token function">git</span> stash show <span class="token string">'stash@{0}'</span> -p
<span class="token function">diff</span> --git a/public/vue/js/portal/common/common.js b/public/vue/js/portal/common/common.js
index <span class="token number">4579074</span><span class="token punctuation">..</span>e83ab24 <span class="token number">100644</span>
index <span class="token number">4579074</span><span class="token punctuation">..</span>e83ab24 <span class="token number">100644</span>
--- a/public/vue/js/portal/common/common.js
+++ b/public/vue/js/portal/common/common.js
@@ -50,6 +50,10 @@ <span class="token builtin class-name">export</span> default <span class="token punctuation">{</span>
             this.peopleWebsocket <span class="token operator">&amp;&amp;</span> this.peopleWebsocket.send<span class="token punctuation">(</span>JSON.stringify<span class="token punctuation">(</span>obj<span class="token punctuation">))</span><span class="token punctuation">;</span>//回复说 在线
           <span class="token punctuation">}</span>
         <span class="token punctuation">}</span>else <span class="token punctuation">{</span>
+          if<span class="token punctuation">(</span>socketData.clearLoginFlag<span class="token punctuation">)</span><span class="token punctuation">{</span>
+            this.tackUnlock<span class="token punctuation">(</span>true<span class="token punctuation">)</span><span class="token punctuation">;</span>
+            <span class="token builtin class-name">return</span><span class="token punctuation">;</span>
+          <span class="token punctuation">}</span>
           if<span class="token punctuation">(</span><span class="token operator">!</span>socketData.validCheck<span class="token punctuation">)</span><span class="token punctuation">{</span>//validCheck为false说明该用户被作废了
</code></pre></div><h4 id="git-stash-drop-stash"><a href="#git-stash-drop-stash" class="header-anchor">#</a> git stash drop <code>&lt;stash&gt;</code></h4> <p>从存储条目列表中删除单个存储条目。如果没有<code>&lt;stash&gt;</code>给出，它将删除最新的一个</p> <div class="language-bash extra-class"><pre class="language-bash"><code> PS D:<span class="token punctuation">\</span>project<span class="token punctuation">\</span>git<span class="token punctuation">\</span>web-hip<span class="token operator">&gt;</span> <span class="token function">git</span> stash drop <span class="token string">'stash@{4}'</span>
Dropped stash@<span class="token punctuation">{</span><span class="token number">4</span><span class="token punctuation">}</span> <span class="token punctuation">(</span>a7c965742435d921d2f43bb553dce83738115089<span class="token punctuation">)</span>
</code></pre></div><h4 id="git-stash-push-m-描述说明"><a href="#git-stash-push-m-描述说明" class="header-anchor">#</a> git stash push -m '描述说明'</h4> <p><strong>注意旧版本不支持 push,则需要用 git stash save '描述说明' 代替</strong>
将您的本地修改保存到新的存储条目中，并将它们回滚到 HEAD（在工作树和索引中）</p> <h4 id="git-stash-pop-stash"><a href="#git-stash-pop-stash" class="header-anchor">#</a> git stash pop <code>&lt;stash&gt;</code></h4> <p>从存储列表中删除一个单独的存储状态并将其应用于当前工作树状态的顶部,若 <code>&lt;stash&gt;</code>没传，值是将 stash 里最新的一个 即 stash@{0}释放出来到本地代码上。</p> <h4 id="git-stash-clear"><a href="#git-stash-clear" class="header-anchor">#</a> git stash clear</h4> <p>删除所有的存储条目</p> <h2 id="branch-分支操作"><a href="#branch-分支操作" class="header-anchor">#</a> branch 分支操作</h2> <h3 id="含义描述"><a href="#含义描述" class="header-anchor">#</a> 含义描述</h3> <ul><li>分支是用来将特性开发绝缘开来的。在你创建仓库的时候，<code>master</code>是“默认的”。在其他分支上进行开发，完成后再将它们合并到主分支上。
<img src="https://img-blog.csdnimg.cn/20200815144423910.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDY1MzMyOQ==,size_16,color_FFFFFF,t_70#pic_center" alt="在这里插入图片描述"></li></ul> <h3 id="操作汇总-2"><a href="#操作汇总-2" class="header-anchor">#</a> 操作汇总</h3> <div class="language-bash extra-class"><pre class="language-bash"><code>usage: <span class="token function">git</span> branch <span class="token punctuation">[</span><span class="token operator">&lt;</span>options<span class="token operator">&gt;</span><span class="token punctuation">]</span> <span class="token punctuation">[</span>-r <span class="token operator">|</span> -a<span class="token punctuation">]</span> <span class="token punctuation">[</span>--merged<span class="token punctuation">]</span> <span class="token punctuation">[</span>--no-merged<span class="token punctuation">]</span>
   or: <span class="token function">git</span> branch <span class="token punctuation">[</span><span class="token operator">&lt;</span>options<span class="token operator">&gt;</span><span class="token punctuation">]</span> <span class="token punctuation">[</span>-l<span class="token punctuation">]</span> <span class="token punctuation">[</span>-f<span class="token punctuation">]</span> <span class="token operator">&lt;</span>branch-name<span class="token operator">&gt;</span> <span class="token punctuation">[</span><span class="token operator">&lt;</span>start-point<span class="token operator">&gt;</span><span class="token punctuation">]</span>
   or: <span class="token function">git</span> branch <span class="token punctuation">[</span><span class="token operator">&lt;</span>options<span class="token operator">&gt;</span><span class="token punctuation">]</span> <span class="token punctuation">[</span>-r<span class="token punctuation">]</span> <span class="token punctuation">(</span>-d <span class="token operator">|</span> -D<span class="token punctuation">)</span> <span class="token operator">&lt;</span>branch-name<span class="token operator">&gt;</span><span class="token punctuation">..</span>.
   or: <span class="token function">git</span> branch <span class="token punctuation">[</span><span class="token operator">&lt;</span>options<span class="token operator">&gt;</span><span class="token punctuation">]</span> <span class="token punctuation">(</span>-m <span class="token operator">|</span> -M<span class="token punctuation">)</span> <span class="token punctuation">[</span><span class="token operator">&lt;</span>old-branch<span class="token operator">&gt;</span><span class="token punctuation">]</span> <span class="token operator">&lt;</span>new-branch<span class="token operator">&gt;</span>
   or: <span class="token function">git</span> branch <span class="token punctuation">[</span><span class="token operator">&lt;</span>options<span class="token operator">&gt;</span><span class="token punctuation">]</span> <span class="token punctuation">(</span>-c <span class="token operator">|</span> -C<span class="token punctuation">)</span> <span class="token punctuation">[</span><span class="token operator">&lt;</span>old-branch<span class="token operator">&gt;</span><span class="token punctuation">]</span> <span class="token operator">&lt;</span>new-branch<span class="token operator">&gt;</span>
   or: <span class="token function">git</span> branch <span class="token punctuation">[</span><span class="token operator">&lt;</span>options<span class="token operator">&gt;</span><span class="token punctuation">]</span> <span class="token punctuation">[</span>-r <span class="token operator">|</span> -a<span class="token punctuation">]</span> <span class="token punctuation">[</span>--points-at<span class="token punctuation">]</span>
   or: <span class="token function">git</span> branch <span class="token punctuation">[</span><span class="token operator">&lt;</span>options<span class="token operator">&gt;</span><span class="token punctuation">]</span> <span class="token punctuation">[</span>-r <span class="token operator">|</span> -a<span class="token punctuation">]</span> <span class="token punctuation">[</span>--format<span class="token punctuation">]</span>
</code></pre></div><h3 id="操作详解-2"><a href="#操作详解-2" class="header-anchor">#</a> 操作详解</h3> <h4 id="git-checkout-b-新分支名称（是以下命令的组合）"><a href="#git-checkout-b-新分支名称（是以下命令的组合）" class="header-anchor">#</a> git checkout -b 新分支名称（是以下命令的组合）</h4> <ul><li><code>git branch 分支名称</code>: 新建本地分支</li> <li><code>git checkout 分支名称</code>: 切换到某一分支</li></ul> <p>创建新的本地分支</p> <h4 id="git-checkout-分支名称"><a href="#git-checkout-分支名称" class="header-anchor">#</a> git checkout 分支名称</h4> <p>切换到某个分支</p> <h3 id="git-branch-d-分支名称-git-branch-d-分支名称"><a href="#git-branch-d-分支名称-git-branch-d-分支名称" class="header-anchor">#</a> git branch -d 分支名称 / git branch -D 分支名称</h3> <p>删除某个分支 (注意不要删除当前所在的分支，比如当前是处在 test1 分支，然后去删 test1 分支，这样是不会成功的)
大小 D 有区别 <code>-D</code>表示强制删除，若本地分支没有合并到其他分支或者没有远程关联分支，则<code>-d</code>会报错<code>The branch '***' is not fully merged</code>,用<code>-D</code>就可以强制删除了。</p> <h4 id="git-branch-a"><a href="#git-branch-a" class="header-anchor">#</a> git branch -a</h4> <p>显示所有的分支（若没看到所有的分支，则先执行<code>git fetch</code>一下）</p> <h4 id="git-branch"><a href="#git-branch" class="header-anchor">#</a> git branch</h4> <p>显示当前的本地分支</p> <h4 id="git-branch-r"><a href="#git-branch-r" class="header-anchor">#</a> git branch -r</h4> <p>显示所有的远程分支</p> <h3 id="本地分支与远程分支的关联操作"><a href="#本地分支与远程分支的关联操作" class="header-anchor">#</a> 本地分支与远程分支的关联操作</h3> <h4 id="git-branch-vv"><a href="#git-branch-vv" class="header-anchor">#</a> git branch -vv</h4> <p>查看本地分支与远程分支的关联关系</p> <p>如下：本地分支【test】跟远程分支【origin/test】关联，而 test2 没有跟远程分支关联</p> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>test<span class="token punctuation">\</span>test<span class="token operator">&gt;</span>git branch -vv
  master d5a8c2d <span class="token punctuation">[</span>origin/master<span class="token punctuation">]</span> deploy
* <span class="token builtin class-name">test</span>   d5a8c2d <span class="token punctuation">[</span>origin/test<span class="token punctuation">]</span> deploy
  test2
</code></pre></div><h4 id="git-branch-u-origin-test-或-git-branch-set-upstream-origin-test"><a href="#git-branch-u-origin-test-或-git-branch-set-upstream-origin-test" class="header-anchor">#</a> <code>git branch -u origin/test</code> 或 <code>git branch --set-upstream origin/test</code></h4> <p>将当前分支跟远程分支【origin/test】建立关联(建立在已经存在远程分支的基础上)</p> <h4 id="git-branch-set-upstream-to-origin-test-test6"><a href="#git-branch-set-upstream-to-origin-test-test6" class="header-anchor">#</a> <code>git branch --set-upstream-to=origin/test test6</code></h4> <p>指定当前分支与远程分支建立关联（此处是本地分支【test6】与远程分支【origin/test】建立关联）</p> <h4 id="git-push-set-upstream-origin-test"><a href="#git-push-set-upstream-origin-test" class="header-anchor">#</a> git push --set-upstream origin test</h4> <p>将本地分支内容合并到远程分支上</p> <p>有两种情况</p> <ul><li>当前打开的本地分支跟远程分支相同，如：都为分支【test】，则不管远程分支有没有创建，则都会把本地分支合并到远程分支【test】上。（如远程分支不存在，则会自动创建）</li> <li>当前打开的本地分支跟远程分支不同，如：本地分支为【test3】,远程分支为【test】,则根据远程分支是否存在做处理
<ul><li>远程分支不存在，则报错。</li> <li>远程分支存在，则会把本地分支【test】合并到远程分支上（注意是本地分支【test】,而不是当前打开的本地分支【test3】）</li></ul></li></ul> <h4 id="git-branch-unset-upstream"><a href="#git-branch-unset-upstream" class="header-anchor">#</a> <code>git branch --unset-upstream</code></h4> <p>解除当前本地分支与远程分支的关联</p> <h4 id="git-push-origin-delete-test3"><a href="#git-push-origin-delete-test3" class="header-anchor">#</a> <code>git push origin --delete test3</code></h4> <p>删除远程分支【test3】</p> <h2 id="commit-命令"><a href="#commit-命令" class="header-anchor">#</a> commit 命令</h2> <h3 id="操作详解-3"><a href="#操作详解-3" class="header-anchor">#</a> 操作详解</h3> <h4 id="git-add"><a href="#git-add" class="header-anchor">#</a> git add .</h4> <p>表示添加新增的文件</p> <h4 id="git-commit-m-提交说明"><a href="#git-commit-m-提交说明" class="header-anchor">#</a> git commit -m '提交说明'</h4> <p>表示提交修改的文件</p> <h4 id="git-reflog"><a href="#git-reflog" class="header-anchor">#</a> git reflog</h4> <p>查看提交的记录</p> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>test<span class="token punctuation">\</span>test<span class="token operator">&gt;</span>git reflog
a806361 <span class="token punctuation">(</span>HEAD -<span class="token operator">&gt;</span> master, origin/master<span class="token punctuation">)</span> HEAD@<span class="token punctuation">{</span><span class="token number">0</span><span class="token punctuation">}</span>: commit: <span class="token string">'&lt;E7&gt;&lt;E4&gt;&lt;A4&gt;'</span>
33c940a HEAD@<span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">}</span>: commit <span class="token punctuation">(</span>initial<span class="token punctuation">)</span>: <span class="token string">'&lt;AC&gt;&lt;AC&gt;'</span>
</code></pre></div><h2 id="回退操作"><a href="#回退操作" class="header-anchor">#</a> 回退操作</h2> <p>两种回退方式</p> <ol><li><code>git reset --hard 版本号</code></li> <li><code>git revert -n 版本号</code></li></ol> <h4 id="git-reset-hard-版本号"><a href="#git-reset-hard-版本号" class="header-anchor">#</a> git reset --hard 版本号</h4> <blockquote><p>回退到上一个版本，可选 <code>--hard</code>/<code>--soft</code>/<code>--mixed</code>. 默认是<code>--mixed</code></p></blockquote> <blockquote><p><code>--mixed</code>: 将<code>Commit History</code>（commit 后的内容）和<code>Working Directory</code>(当前本地修改的内容)统一重置回到 <code>Working Directory</code>状态中，不移除当前的变更内容；</p></blockquote> <blockquote><p><code>--hard</code>: 直接清空<code>Commit History</code>（commit 后的内容）和<code>Working Directory</code>(当前本地修改的内容)</p></blockquote> <blockquote><p><code>--soft</code>: 重置的同时保留<code>Working Directory</code>(当前本地修改的内容) 和将<code>Commit History</code>（commit 后的内容）重置为<code>Index/Stage</code>暂存区域</p></blockquote> <ol><li>先查询版本号 <code>git log</code></li></ol> <p>commit 后面那串数字就是版本号</p> <div class="language-bash extra-class"><pre class="language-bash"><code>guo@guoMacBook-Pro blog % <span class="token function">git</span> log
commit ee59be94063350913a9ccd9e0c639f2ccd368dca <span class="token punctuation">(</span>HEAD -<span class="token operator">&gt;</span> master, origin/master, origin/HEAD<span class="token punctuation">)</span>
Author: guo <span class="token operator">&lt;</span>guoran@gaoding.com<span class="token operator">&gt;</span>
Date:   Wed Jul <span class="token number">14</span> <span class="token number">15</span>:54:41 <span class="token number">2021</span> +0800
   fix: 这个是最新提交的

commit a0ec03d64bab2a220678252d5b1e5aeb608f6ae0
Author: wenbintian <span class="token operator">&lt;</span><span class="token number">972619117</span>@qq.com<span class="token operator">&gt;</span>
Date:   Wed Jul <span class="token number">14</span> 07:53:37 <span class="token number">2021</span> +0000
   feat: 提交文件text1

commit db7a0d665faa9ef9f52878a839aeb8c78f957615
Author: wenbintian <span class="token operator">&lt;</span><span class="token number">972619117</span>@qq.com<span class="token operator">&gt;</span>
Date:   Wed Jul <span class="token number">12</span> 07:52:37 <span class="token number">2021</span> +0000
   feat: 提交文件text2
</code></pre></div><ol start="2"><li><code>git reset --hard a0ec03d64bab2a220678252d5b1e5aeb608f6ae0</code></li></ol> <p>代表回退到这个版本，然后<strong>在这个版本之后的代码都会被还原掉，commit 记录也会找不到（但是可以在 <code>git reflog</code> 找到记录）</strong>，操作需要<strong>谨慎</strong></p> <ol start="3"><li>再次执行 <code>git log</code>, 最新的<code>commit</code>记录会被清掉（可在<code>git reflog</code>中找到记录）。</li></ol> <div class="language-bash extra-class"><pre class="language-bash"><code>guo@guoMacBook-Pro blog % <span class="token function">git</span> log
commit a0ec03d64bab2a220678252d5b1e5aeb608f6ae0
Author: wenbintian <span class="token operator">&lt;</span><span class="token number">972619117</span>@qq.com<span class="token operator">&gt;</span>
Date:   Wed Jul <span class="token number">14</span> 07:53:37 <span class="token number">2021</span> +0000
   feat: 提交文件text1

commit db7a0d665faa9ef9f52878a839aeb8c78f957615
Author: wenbintian <span class="token operator">&lt;</span><span class="token number">972619117</span>@qq.com<span class="token operator">&gt;</span>
Date:   Wed Jul <span class="token number">12</span> 07:52:37 <span class="token number">2021</span> +0000
   feat: 提交文件text2
</code></pre></div><h4 id="git-revert-n-版本号"><a href="#git-revert-n-版本号" class="header-anchor">#</a> git revert -n 版本号</h4> <p>将某一个版本<strong>反做</strong>，会增加一条新的<code>commit</code>记录。</p> <ol><li>先查询版本号<code>git log</code></li></ol> <div class="language-bash extra-class"><pre class="language-bash"><code>guo@guoMacBook-Pro blog % <span class="token function">git</span> log
commit ee59be94063350913a9ccd9e0c639f2ccd368dca <span class="token punctuation">(</span>HEAD -<span class="token operator">&gt;</span> master, origin/master, origin/HEAD<span class="token punctuation">)</span>
Author: guo <span class="token operator">&lt;</span>guoran@gaoding.com<span class="token operator">&gt;</span>
Date:   Wed Jul <span class="token number">14</span> <span class="token number">15</span>:54:41 <span class="token number">2021</span> +0800
   fix: 这个是最新提交的

commit a0ec03d64bab2a220678252d5b1e5aeb608f6ae0
Author: wenbintian <span class="token operator">&lt;</span><span class="token number">972619117</span>@qq.com<span class="token operator">&gt;</span>
Date:   Wed Jul <span class="token number">14</span> 07:53:37 <span class="token number">2021</span> +0000
   feat: 提交文件text1

commit db7a0d665faa9ef9f52878a839aeb8c78f957615
Author: wenbintian <span class="token operator">&lt;</span><span class="token number">972619117</span>@qq.com<span class="token operator">&gt;</span>
Date:   Wed Jul <span class="token number">12</span> 07:52:37 <span class="token number">2021</span> +0000
   feat: 提交文件text2
</code></pre></div><ol start="2"><li><code>git revert -n a0ec03d64bab2a220678252d5b1e5aeb608f6ae0</code></li></ol> <p>代表反做到这个版本，会生成新的代码，然后再进行 <code>git commit / git pull</code>操作，此时有新的<code>commit</code>记录</p> <ol start="3"><li>再次执行 <code>git log</code>, 会产生最新的<code>commit</code>记录</li></ol> <div class="language-bash extra-class"><pre class="language-bash"><code>guo@guoMacBook-Pro blog % <span class="token function">git</span> log
commit 58f0ffbfdf8a803e520ad3cc62140f4482fc19a6 <span class="token punctuation">(</span>HEAD -<span class="token operator">&gt;</span> master, origin/master, origin/HEAD<span class="token punctuation">)</span>
Author: guo <span class="token operator">&lt;</span>guoran@gaoding.com<span class="token operator">&gt;</span>
Date:   Wed Jul <span class="token number">16</span> <span class="token number">13</span>:53:42 <span class="token number">2021</span> +0800
   fix: 这个是还原【提交文件text1】的最新代码

commit ee59be94063350913a9ccd9e0c639f2ccd368dca <span class="token punctuation">(</span>HEAD -<span class="token operator">&gt;</span> master, origin/master, origin/HEAD<span class="token punctuation">)</span>
Author: guo <span class="token operator">&lt;</span>guoran@gaoding.com<span class="token operator">&gt;</span>
Date:   Wed Jul <span class="token number">14</span> <span class="token number">15</span>:54:41 <span class="token number">2021</span> +0800
   fix: 这个是最新提交的

commit a0ec03d64bab2a220678252d5b1e5aeb608f6ae0
Author: wenbintian <span class="token operator">&lt;</span><span class="token number">972619117</span>@qq.com<span class="token operator">&gt;</span>
Date:   Wed Jul <span class="token number">14</span> 07:53:37 <span class="token number">2021</span> +0000
   feat: 提交文件text1

commit db7a0d665faa9ef9f52878a839aeb8c78f957615
Author: wenbintian <span class="token operator">&lt;</span><span class="token number">972619117</span>@qq.com<span class="token operator">&gt;</span>
Date:   Wed Jul <span class="token number">12</span> 07:52:37 <span class="token number">2021</span> +0000
   feat: 提交文件text2
</code></pre></div><h2 id="cherry-pick-操作"><a href="#cherry-pick-操作" class="header-anchor">#</a> cherry-pick 操作</h2> <h3 id="用途"><a href="#用途" class="header-anchor">#</a> 用途</h3> <p>用于合并部分的<code>commit</code>代码</p> <h3 id="操作"><a href="#操作" class="header-anchor">#</a> 操作</h3> <ol><li><code>git reflog</code>
查看需要 pick 的 <code>commitID</code></li> <li><code>git cherry-pick commitID</code>
直接把要的<code>commitID</code>合并到当前分支</li> <li><code>git cherry-pick --abort</code>
撤销当前合并的 commit</li></ol> <h2 id="worktree-操作"><a href="#worktree-操作" class="header-anchor">#</a> worktree 操作</h2> <h3 id="用途-2"><a href="#用途-2" class="header-anchor">#</a> 用途</h3> <p>可以同时维护多个分支代码、可以对比不同分支代码的行为。</p> <h3 id="操作汇总-3"><a href="#操作汇总-3" class="header-anchor">#</a> 操作汇总</h3> <div class="language-bash extra-class"><pre class="language-bash"><code>usage: <span class="token function">git</span> worktree <span class="token function">add</span> <span class="token punctuation">[</span><span class="token operator">&lt;</span>options<span class="token operator">&gt;</span><span class="token punctuation">]</span> <span class="token operator">&lt;</span>path<span class="token operator">&gt;</span> <span class="token punctuation">[</span><span class="token operator">&lt;</span>commit-ish<span class="token operator">&gt;</span><span class="token punctuation">]</span>
   or: <span class="token function">git</span> worktree list <span class="token punctuation">[</span><span class="token operator">&lt;</span>options<span class="token operator">&gt;</span><span class="token punctuation">]</span>
   or: <span class="token function">git</span> worktree lock <span class="token punctuation">[</span><span class="token operator">&lt;</span>options<span class="token operator">&gt;</span><span class="token punctuation">]</span> <span class="token operator">&lt;</span>path<span class="token operator">&gt;</span>
   or: <span class="token function">git</span> worktree move <span class="token operator">&lt;</span>worktree<span class="token operator">&gt;</span> <span class="token operator">&lt;</span>new-path<span class="token operator">&gt;</span>
   or: <span class="token function">git</span> worktree prune <span class="token punctuation">[</span><span class="token operator">&lt;</span>options<span class="token operator">&gt;</span><span class="token punctuation">]</span>
   or: <span class="token function">git</span> worktree remove <span class="token punctuation">[</span><span class="token operator">&lt;</span>options<span class="token operator">&gt;</span><span class="token punctuation">]</span> <span class="token operator">&lt;</span>worktree<span class="token operator">&gt;</span>
   or: <span class="token function">git</span> worktree unlock <span class="token operator">&lt;</span>path<span class="token operator">&gt;</span>
</code></pre></div><h3 id="操作详解-4"><a href="#操作详解-4" class="header-anchor">#</a> 操作详解</h3> <h4 id="git-worktree-add-新路径"><a href="#git-worktree-add-新路径" class="header-anchor">#</a> git worktree add [新路径]</h4> <p>基于当前分支，新建一个 worktree 目录，新的分支名就是新建目录的名称。一般新路径都是 <code>../</code>，这样才会与当前项目同目录。</p> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>project<span class="token punctuation">\</span>git<span class="token punctuation">\</span>web-portal<span class="token operator">&gt;</span> <span class="token function">git</span> worktree <span class="token function">add</span> <span class="token punctuation">..</span>/test-work
</code></pre></div><h4 id="git-worktree-add-新路径-b-新分支名-a"><a href="#git-worktree-add-新路径-b-新分支名-a" class="header-anchor">#</a> git worktree add &lt;新路径&gt; -b &lt;新分支名 A&gt;</h4> <p>基于当前分支，新建一个 worktree 目录，新的分支名就是&lt;新分支名 A&gt;。如下分支名为 test-tag。</p> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>project<span class="token punctuation">\</span>git<span class="token punctuation">\</span>web-portal<span class="token operator">&gt;</span> <span class="token function">git</span> worktree <span class="token function">add</span> <span class="token punctuation">..</span>/test-work test-tag
</code></pre></div><h4 id="git-worktree-add-新路径-b-新分支名-a-迁出的分支名-a"><a href="#git-worktree-add-新路径-b-新分支名-a-迁出的分支名-a" class="header-anchor">#</a> git worktree add &lt;新路径&gt; -b &lt;新分支名 A&gt; &lt;迁出的分支名 A&gt;</h4> <p>基于指定的源分支&lt;迁出的分支名 A&gt;，新建一个 worktree 目录，新的分支名就是&lt;新分支名 A&gt;。如下基于 从 mater 分支迁出一个分支名为 test-tag。</p> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>project<span class="token punctuation">\</span>git<span class="token punctuation">\</span>web-portal<span class="token operator">&gt;</span> <span class="token function">git</span> worktree <span class="token function">add</span> <span class="token punctuation">..</span>/test-work test-tag master
</code></pre></div><h4 id="git-worktree-remove-新分支名-a"><a href="#git-worktree-remove-新分支名-a" class="header-anchor">#</a> git worktree remove &lt;新分支名 A&gt;</h4> <p>移除工作区分支&lt;新分支名 A&gt;</p> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>project<span class="token punctuation">\</span>git<span class="token punctuation">\</span>web-portal<span class="token operator">&gt;</span> <span class="token function">git</span> worktree remove test-tag
</code></pre></div><h4 id="git-worktree-list"><a href="#git-worktree-list" class="header-anchor">#</a> git worktree list</h4> <p>显示当前有多少个工作区</p> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>project<span class="token punctuation">\</span>git<span class="token punctuation">\</span>web-portal<span class="token operator">&gt;</span> <span class="token function">git</span> worktree list
</code></pre></div><h2 id="统计git项目行数"><a href="#统计git项目行数" class="header-anchor">#</a> 统计git项目行数</h2> <h3 id="操作详解-5"><a href="#操作详解-5" class="header-anchor">#</a> 操作详解</h3> <h4 id="显示项目文件的所有文件列表、及行数（已经删除的文件显示为空）"><a href="#显示项目文件的所有文件列表、及行数（已经删除的文件显示为空）" class="header-anchor">#</a> 显示项目文件的所有文件列表、及行数（已经删除的文件显示为空）</h4> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>project<span class="token punctuation">\</span>git<span class="token punctuation">\</span>web-portal<span class="token operator">&gt;</span> <span class="token function">git</span> ls-files <span class="token operator">|</span> <span class="token function">xargs</span> <span class="token function">wc</span> -l
</code></pre></div><h4 id="显示某文件夹下的代码量"><a href="#显示某文件夹下的代码量" class="header-anchor">#</a> 显示某文件夹下的代码量</h4> <p><code>src base</code> 代表 base 文件夹下的</p> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>project<span class="token punctuation">\</span>git<span class="token punctuation">\</span>web-portal<span class="token operator">&gt;</span> <span class="token function">git</span> ls-files src base <span class="token operator">|</span> <span class="token function">xargs</span> <span class="token function">wc</span> -l
</code></pre></div><h4 id="统计base下的文件夹并排除某些文件或文件夹"><a href="#统计base下的文件夹并排除某些文件或文件夹" class="header-anchor">#</a> 统计base下的文件夹并排除某些文件或文件夹</h4> <p><code>src base</code> 代表 base 文件夹下的
<code>grep -Ev 'file|.png|.zip'</code> 代表排除 file 文件夹和 png/zip 文件</p> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>project<span class="token punctuation">\</span>git<span class="token punctuation">\</span>web-portal<span class="token operator">&gt;</span> <span class="token function">git</span> ls-files src base <span class="token operator">|</span> <span class="token function">grep</span> -Ev <span class="token string">'file|.png|.zip'</span> <span class="token operator">|</span> <span class="token function">xargs</span> <span class="token function">wc</span> -l
</code></pre></div><h4 id="显示项目代码总行数"><a href="#显示项目代码总行数" class="header-anchor">#</a> 显示项目代码总行数</h4> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>project<span class="token punctuation">\</span>git<span class="token punctuation">\</span>web-portal<span class="token operator">&gt;</span> <span class="token function">git</span> ls-files <span class="token operator">|</span> <span class="token function">xargs</span> <span class="token function">cat</span> <span class="token operator">|</span> <span class="token function">wc</span> -l
</code></pre></div><h4 id="显示项目文件列表"><a href="#显示项目文件列表" class="header-anchor">#</a> 显示项目文件列表</h4> <div class="language-bash extra-class"><pre class="language-bash"><code>D:<span class="token punctuation">\</span>project<span class="token punctuation">\</span>git<span class="token punctuation">\</span>web-portal<span class="token operator">&gt;</span> <span class="token function">git</span> ls-files
</code></pre></div><h2 id="参考"><a href="#参考" class="header-anchor">#</a> 参考</h2> <p><a href="https://www.bootcss.com/p/git-guide/" target="_blank" rel="noopener noreferrer">git 使用建议指南<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <p><a href="https://git-scm.com/book/zh/v2" target="_blank" rel="noopener noreferrer">Git - Book<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <p><a href="https://www.cnblogs.com/tocy/p/git-stash-reference.html" target="_blank" rel="noopener noreferrer">git-stash 用法小结<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <p><a href="https://www.jianshu.com/p/c2ec5f06cf1a" target="_blank" rel="noopener noreferrer">git-reset 三种模式<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">最后一次修改时间:</span> <span class="time">7/18/2022, 6:15:32 PM</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/blog/knowledge/book/knowjs3.html" class="prev">
        你不知道的JavaScript(下)
      </a></span> <span class="next"><a href="/blog/knowledge/tool/tool2.html">
        移动端适配之postcss-px-to-viewport
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/blog/assets/js/app.2a047d56.js" defer></script><script src="/blog/assets/js/2.cc145974.js" defer></script><script src="/blog/assets/js/36.7239d917.js" defer></script>
  </body>
</html>
